package com.carbeauty.common.exception;

/**
 * 资源不存在异常类
 * 
 * 用于处理资源不存在的情况:
 * - 数据库记录不存在
 * - 文件不存在
 * - 页面不存在
 * - API接口不存在
 * 
 * @author CarBeauty Team
 */
public class ResourceNotFoundException extends RuntimeException {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 资源类型
     */
    private String resourceType;
    
    /**
     * 资源标识
     */
    private String resourceId;
    
    // ==================== 构造方法 ====================
    
    public ResourceNotFoundException(String message) {
        super(message);
    }
    
    public ResourceNotFoundException(String resourceType, String resourceId) {
        super(resourceType + " 不存在，ID: " + resourceId);
        this.resourceType = resourceType;
        this.resourceId = resourceId;
    }
    
    public ResourceNotFoundException(String message, Throwable cause) {
        super(message, cause);
    }
    
    public ResourceNotFoundException(String resourceType, String resourceId, Throwable cause) {
        super(resourceType + " 不存在，ID: " + resourceId, cause);
        this.resourceType = resourceType;
        this.resourceId = resourceId;
    }
    
    // ==================== Getter/Setter ====================
    
    public String getResourceType() {
        return resourceType;
    }
    
    public void setResourceType(String resourceType) {
        this.resourceType = resourceType;
    }
    
    public String getResourceId() {
        return resourceId;
    }
    
    public void setResourceId(String resourceId) {
        this.resourceId = resourceId;
    }
    
    // ==================== 静态工厂方法 ====================
    
    /**
     * 客户不存在
     */
    public static ResourceNotFoundException customer(Long customerId) {
        return new ResourceNotFoundException("客户", String.valueOf(customerId));
    }
    
    /**
     * 用户不存在
     */
    public static ResourceNotFoundException user(Long userId) {
        return new ResourceNotFoundException("用户", String.valueOf(userId));
    }
    
    /**
     * 订单不存在
     */
    public static ResourceNotFoundException order(Long orderId) {
        return new ResourceNotFoundException("订单", String.valueOf(orderId));
    }
    
    /**
     * 服务项目不存在
     */
    public static ResourceNotFoundException service(Long serviceId) {
        return new ResourceNotFoundException("服务项目", String.valueOf(serviceId));
    }
    
    /**
     * 材料不存在
     */
    public static ResourceNotFoundException material(Long materialId) {
        return new ResourceNotFoundException("材料", String.valueOf(materialId));
    }
    
    /**
     * 字典不存在
     */
    public static ResourceNotFoundException dictionary(Long dictId) {
        return new ResourceNotFoundException("字典", String.valueOf(dictId));
    }
    
    /**
     * 文件不存在
     */
    public static ResourceNotFoundException file(String fileName) {
        return new ResourceNotFoundException("文件", fileName);
    }
    
    /**
     * 页面不存在
     */
    public static ResourceNotFoundException page(String pagePath) {
        return new ResourceNotFoundException("页面", pagePath);
    }
}
